﻿using RightControl.IRepository;
using RightControl.IService;
using RightControl.Model;
using RightControl.Repository;
using System.Collections.Generic;

namespace RightControl.Service {
    public class ShipService : BaseService<ShipTemplate>, IShipService {
        public IShipRepository repository { get; set; }

        public dynamic GetTemplateList(int userId,int platForm) {
            string sql = " SELECT Id,TemplateName FROM `ship_template`";
            sql += " where CreateBy=" + userId;
            sql += " And PlatForm=" + platForm;
            sql += " And Status=1";

            return repository.GetTemplateList(sql);
        }
        
        public dynamic GetListByFilter(ShipTemplate filter, PageInfo pageInfo) {    
            string _where = " where 1=1";
            if (filter.PlatForm > 0) {
                _where += string.Format(" and PlatForm = {0}", filter.PlatForm);
            }
            _where += string.Format(" and CreateBy = {0} and Status=1", filter.CreateBy);
           
            return GetListByFilter(filter, pageInfo, _where);
        }

        public bool Delete(ShipTemplate filter) {
            string _where = " where 1=1";
            _where += string.Format(" and Id = {0} ", filter.Id);
            _where += string.Format(" and CreateBy = {0} and Status=1", filter.CreateBy);
            _where += string.Format(" and PlatForm = {0} ", filter.PlatForm);
            return DeleteByWhere(_where);
        }
    }
}